# DBConnectionAPI

DBConnectionAPI is an ASP.NET Core REST API that returns ready-to-use database connection strings for Oracle, SQL Server and PostgreSQL targets. It builds each string from a per-database-type template and a per-user secure credential held in the SAIF Environment API, so callers do not store templates or credentials themselves. Oracle and SQL Server strings are validated with a connectivity probe and cached in process memory. An administrative surface returns the individual credential parts for troubleshooting.

> Responses carry credential material. Protect them accordingly.

## Getting Started

### Prerequisites

- [.NET 10 SDK](https://dotnet.microsoft.com/download) (the project targets `net10.0`)
- Access to the SAIF NuGet feed, to restore SAIF packages
- Access to the SAIF Environment API for the target environment

### Installation

```powershell
git clone <repository-url>
cd Framework.CoreServices.DBConnectionAPI\DBConnectionAPI
dotnet restore DBConnectionAPI.sln
```

### Run locally

```powershell
dotnet run --project DBConnectionAPI\DBConnectionAPI.csproj
```

## API overview

| Endpoint | Purpose |
| --- | --- |
| `GET /v1/Connections/SQL/{server}/{instance}/{username}` | Validated, cached SQL Server connection string |
| `GET /v1/Connections/ORA/{instance}/{username}` | Validated, cached Oracle connection string |
| `GET /v1/Connections/PostgreSQL/{instance}/{username}` | Composed PostgreSQL connection string |
| `POST /v1/Admin/GetSqlConnectionInfo` | Credential parts for SQL Server |
| `POST /v1/Admin/GetOracleConnectionInfo` | Credential parts for Oracle |
| `POST /v1/Admin/GetPostgresConnectionInfo` | Credential parts for PostgreSQL |

See the [endpoint reference](docs/apis/dbconnectionapi/endpoints.md) for details.

## Build and Test

```powershell
cd DBConnectionAPI
dotnet build DBConnectionAPI.sln
dotnet test DBConnectionAPI.sln
```

## Project structure

| Path | Description |
| --- | --- |
| `DBConnectionAPI/DBConnectionAPI` | API host, controllers and connection services |
| `DBConnectionAPI/DBConnectionAPI.Tests` | Unit tests |
| `docs` | Generated documentation |

## Documentation

Full documentation is available at [docs/index.md](docs/index.md).

## Generated libraries

| Library | Purpose | Index | Documentation |
| --- | --- | --- | --- |
| DBConnectionAPI | ASP.NET Core REST API host for composing database connection strings. | [Index](docs/libraries/index.md) | [Documentation](docs/apis/dbconnectionapi/index.md) |

_Last updated: 2026-10-12_

## Contributing

1. Create a branch from `master`.
2. Make your change and add or update tests.
3. Run `dotnet build` and `dotnet test` and confirm both pass.
4. Open a pull request for review.

## Sources
- DBConnectionAPI/DBConnectionAPI/DBConnectionAPI.csproj
- docs/apis/dbconnectionapi/index.md
